import 'package:flutter/material.dart';
import 'package:get/get.dart';
import 'package:wangziyi/pages/app_home/product_search/product_search_view.dart';
import 'package:wangziyi/widget/my_text.dart';
import 'package:waterfall_flow/waterfall_flow.dart';

import 'app_home_logic.dart';
import 'app_home_state.dart';
import 'product_details/product_details_view.dart';

class AppHomePage extends StatelessWidget {
  final AppHomeLogic logic = Get.put(AppHomeLogic());
  final AppHomeState state = Get.find<AppHomeLogic>().state;

  @override
  Widget build(BuildContext context) {
    return Scaffold(appBar: AppBar(
      leading: IconButton(
        icon: Icon(Icons.aspect_ratio_outlined), onPressed: () {},),
      centerTitle: true,
      title: GestureDetector(
        child: Container(
          height: 36,
          decoration: BoxDecoration(
              border: Border.all(width: 2, color: Colors.white),
              borderRadius: BorderRadius.all(Radius.circular(50))
          ),
          child: Row(
            children: <Widget>[
              SizedBox(width: 10),
              Icon(Icons.search_rounded),
              SizedBox(width: 5),
              Text('物理长高'),
              Expanded(child: Text('')),
              Icon(Icons.camera_alt_outlined),
              SizedBox(width: 10),
              Container(
                  width: 70,
                  decoration: BoxDecoration(
                      borderRadius: BorderRadius.all(Radius.circular(50)),
                      color: Colors.white),
                  child: Center(child: Text('搜索', style: TextStyle(
                      color: Colors.black,
                      fontSize: 16,
                      fontWeight: FontWeight.w900)))
              )
            ],
          ),
        ),
        onTap: () => Get.to(ProductSearchPage()),
      ),
    ),
      body: Container(
        padding: EdgeInsets.only(left: 10,right: 10),
        color: Color(0xf44dedede),
        child: WaterfallFlow.builder(
          itemCount: state.imgList.length,
            gridDelegate: SliverWaterfallFlowDelegateWithFixedCrossAxisCount(

              crossAxisCount: 2,
              mainAxisSpacing: 10,
              crossAxisSpacing: 10
            ), itemBuilder: (context,index){
            return GestureDetector(
              child: Container(

                decoration: BoxDecoration(
                    color: Colors.white,
                  borderRadius: BorderRadius.all(Radius.circular(7))
                ),
                child: Column(
                children: <Widget>[
                  Image.network(state.imgList[index]),
                 Container(
                   margin: EdgeInsets.all(10),
                    width: double.infinity,
                    child: Column(
                      crossAxisAlignment:CrossAxisAlignment.start ,
                      children: <Widget>[
                        Text('标题',style: TextStyle(color: Colors.black,fontSize: 20,fontWeight: FontWeight.w900),),
                        Row(children: [
                          Text(state.money,style: TextStyle(color: Colors.red,fontSize:22,fontWeight: FontWeight.w900),),
                          SizedBox(width: 5,),
                          Text('99人购买',style: TextStyle(color: Colors.grey,fontWeight: FontWeight.w900),)

                        ],)
                      ],

                    ),

                  )
                ],
              ),),
              onTap: (){state.productIndex.value=index;Get.to(()=>ProductDetailsPage());},
            );
        }),
      ),
    );
  }
}
